package routers

import (
	"evtest/controller/api"
	"evtest/setting"
	"github.com/gin-gonic/gin"
	"net/http"
)

func InitRouter() *gin.Engine {
	r := gin.New()

	r.Use(gin.Logger())
	r.Use(gin.Recovery())

	gin.SetMode(setting.ServerSetting.RunMode)

	r.NoMethod(handleNotFound)
	r.NoRoute(handleNotFound)

	r.GET("/querytoken", api.QueryToken)
	r.GET("/stationinfos", api.StationInfos)

	return r
}

func handleNotFound(c *gin.Context) {
	meta := map[string]interface{}{
		"status": 404,
		"msg":    c.Request.Method + " " + c.Request.URL.String(),
	}
	c.JSON(http.StatusOK, gin.H{
		"meta": meta,
		"data": nil,
	})
	return
}
